package com.gec.zhs.controller;

import com.gec.zhs.annotation.ZhsLogin;
import com.gec.zhs.entity.dto.TokenUserInfoDto;
import com.gec.zhs.entity.pojo.VideoPlayHistory;
import com.gec.zhs.entity.query.VideoPlayHistoryQuery;
import com.gec.zhs.entity.vo.PaginationResultVO;
import com.gec.zhs.entity.vo.ResponseVO;
import com.gec.zhs.service.VideoPlayHistoryService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhs
 * @version 1.0
 * @date 2025-03-09
 * @description
 */
@RestController
@RequestMapping("/history")
public class VideoHistoryController extends ABaseController{

    @Autowired
    private VideoPlayHistoryService videoPlayHistoryService;

    @ApiOperation("获取历史记录")
    @RequestMapping("/loadHistory")
    @ZhsLogin(checkLogin = true)
    public ResponseVO loadHistory(Integer pageNo){
        TokenUserInfoDto tokenUserInfoDto = getTokenUserInfoDto();

        VideoPlayHistoryQuery videoPlayHistoryQuery = new VideoPlayHistoryQuery();
        videoPlayHistoryQuery.setUserId(tokenUserInfoDto.getUserId());
        videoPlayHistoryQuery.setPageNo(pageNo);
        videoPlayHistoryQuery.setOrderBy("last_update_time desc");
        videoPlayHistoryQuery.setQueryVideoDetail(true);

        PaginationResultVO<VideoPlayHistory> page = videoPlayHistoryService.findListByPage(videoPlayHistoryQuery);

        return getSuccessResponseVO(page);
    }

    @ApiOperation("清理全部的历史记录")
    @RequestMapping("/cleanHistory")
    @ZhsLogin(checkLogin = true)
    public ResponseVO cleanHistory(){
        TokenUserInfoDto tokenUserInfoDto = getTokenUserInfoDto();

        VideoPlayHistoryQuery videoPlayHistoryQuery = new VideoPlayHistoryQuery();
        videoPlayHistoryQuery.setUserId(tokenUserInfoDto.getUserId());
        videoPlayHistoryService.deleteByParam(videoPlayHistoryQuery);
        return getSuccessResponseVO(null);
    }

    @ApiOperation("清理全部的历史记录")
    @RequestMapping("/delHistory")
    @ZhsLogin(checkLogin = true)
    public ResponseVO delHistory(String videoId){
        TokenUserInfoDto tokenUserInfoDto = getTokenUserInfoDto();
        videoPlayHistoryService.deleteVideoPlayHistoryByUserIdAndVideoId(tokenUserInfoDto.getUserId(), videoId);
        return getSuccessResponseVO(null);
    }


}
